package com.javaweb.dao.impl;

import com.javaweb.dao.TagDao;
import com.javaweb.model.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class TagDaoImpl implements TagDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int insert(Tag tag){
        String sql = "INSERT INTO tb_tag (id,name,create_Time,update_Time) VALUES (?,?,?,?)";
        Object [] args = new Object[]{
                tag.getId(),
                tag.getName(),
                new java.sql.Date(tag.getCreateTime().getTime()),
                new java.sql.Date(tag.getUpdateTime().getTime())}                               ;
        return jdbcTemplate.update(sql, args);
    }

    @Override
    public int insertArticleTag(Integer articleId,Integer tagId){
        String sql = "INSERT INTO tb_article_tag (article_id, tag_id) VALUES (?,?)";
        Object [] args = new Object[]{articleId, tagId};
        return jdbcTemplate.update(sql,args);
    }
}